﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Coolite.Ext.Web;
using QFD.Controller;

namespace QFD.View.Coorporacao
{
    public partial class grdCoorporacao : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Ext.IsAjaxRequest)
            {
                this.StoreCoorporacao.DataSource = ControllerCoorporacao.getListaCoorporacao();
                this.StoreCoorporacao.DataBind();
            }
        }

        public Store GridStore
        {
            get;
            set;
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            this.coorporacao.GridStore = this.StoreCoorporacao;
            this.GridStore = this.StoreCoorporacao;
        }

        protected void Refresh(object sender, StoreRefreshDataEventArgs e)
        {
            this.StoreCoorporacao.DataSource = ControllerCoorporacao.getListaCoorporacao();
            this.StoreCoorporacao.DataBind();
        }

        protected void EditarCoorporacao(object sender, AjaxEventArgs e)
        {
            string cdCoorporacao = e.ExtraParams["cdCoorporacao"];
            this.coorporacao.SetCoorporacao(ControllerCoorporacao.getByCoorporacao(int.Parse(cdCoorporacao)));
            this.coorporacao.ShowCoorporacao();
        }

        protected void ConfirmDeleteCoorporacao(object sender, AjaxEventArgs e)
        {
            string cdCoorporacao = e.ExtraParams["cdCoorporacao"];
            COORPORACAO coorp = ControllerCoorporacao.getByCoorporacao(int.Parse(cdCoorporacao));
            ControllerCoorporacao.deleteCoorporacao(coorp);
            this.GridStore.AddScript(string.Format("{0}.reload();", this.GridStore.ClientID));
            Ext.Msg.Alert("Alerta!", "Coorporação <b>" + coorp.NMCOORPORACAO + " </b> excluído com sucesso!").Show();
        }
    }
}